package com.example.demo.controller;

import com.example.demo.dao.OrderDao;
import com.example.demo.model.OrderItem;
import com.example.demo.model.corder;
import com.example.demo.service.impl.Orderimpl;
import com.example.demo.util.JsonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;
import java.util.Date;

@RestController
public class payController extends BaseController{

    @Resource
    OrderDao orderDao;

    @GetMapping("/pay")
    public JsonResult<String> payment(HttpSession session){
        Integer uid = getUidFromSession(session);
        corder data = orderDao.findOrder(uid);
        OrderItem orderItem=orderDao.findOrderItem(data.getOid());
        String payUrl = "http://localhost:8080/alipay/pay?subject=" +orderItem.getTitle()+ "&traceNo=" +data.getOid()+ "&totalAmount=" + data.getTotalPrice();
        return new JsonResult<>(OK,payUrl);
    }
}
